<?php
 class Companies extends UaModel {
 	var $name = "Company";
	var $common_cols = "Company.id AS ID, AS MemberID,industry_id AS CompanyIndustryId,style_id AS Style,Company.name AS CompanyName,Company.description AS Description,main_prod AS MainProduct,boss_name AS Leader,tel AS Tel,mobile AS MobilePhone,link_man AS Linker,fax AS Fax,found_date AS FoundDate,email AS CompanyEmail,Company.*";
	var $alias_cols = "CONCAT(telcode,'-',telzone,'-',tel) AS MixTel,CONCAT(faxcode,'-',faxzone,'-',fax) AS MixFax";

 	var $manage_type = array(1=>"生产型",2=>"贸易型",3=>"服务型",4=>"政府或其他机构");
 	var $main_market = array(1=>"大陆", 2=>"港澳台", 3=>"北美", 4=>"南美", 5=>"欧洲",6=>"亚洲", 7=>"非洲", 8=>"大洋洲",9=>"其他市场");
 	var $company_funds = array(
		0=>"**不公开**",1=>"人民币 10万元之下",
		2=>"人民币 10万-30万",3=>"人民币 30万-50万",
		4=>"人民币 50万-100万",5=>"人民币 100万-300万",
		6=>"人民币 300万-500万",7=>"人民币 500万-1000万",
		8=>"人民币 1000 万元/年-5000 万元/年",9=>"人民币 5000 万元/年-1 亿元/年",
		9=>"其他",
		);
 	var $year_annuals = array(
		0=>"**不公开**",1=>"人民币 10万元之下/年",
		2=>"人民币 10万-30万/年",3=>"人民币 30万-50万/年",
		4=>"人民币 50万-100万/年",5=>"人民币 100万-300万/年",
		6=>"人民币 300万-500万/年",7=>"人民币 500万-1000万/年",
		8=>"人民币 1000万-5000万/年",9=>"人民币 5000万以上/年",
		9=>"其他",
		);
	var $economic_type = array("请选择","国有企业",
		"集体企业",
		"股份合作企业",
		"联营企业",
		"国有联营企业",
		"集体联营企业",
		"国有与集体联营企业",
		"其他联营企业",
		"有限责任公司",
		"国有独资的有限责任公司",
		"其他有限责任公司",
		"股份有限公司",
		"私营企业",
		"私营独资企业",
		"私营合作企业",
		"私营有限责任公司",
		"私营股份有限公司",
		"个人独资企业",
		"与港、澳、台商合资经营企业",
		"与港、澳、台商合作经营企业",
		"港、澳、台商独资经营企业",
		"港、澳、台商投资股份有限公司",
		"中外合资经营企业",
		"中外合作经营企业",
		"外商独资企业",
		"外商投资股份有限公司",
		"非盈利组织",
		"其他",
		);
	var $company_status = array("0"=>"无效","1"=>"有效","2"=>"等待审核","3"=>"审核不通过");
	var $employee_amount = array(
	0=>"**不公开**",
	1=>"5 人以下",2=>"5 - 10 人",3=>"11 - 50 人",4=>"51 - 100 人",5=>"101 -500 人",6=>"501- 1000 人",7=>"1000 人以上");
	var $menu = null;
	var $configs = null;


 	function Companies()
 	{
 		//$this->setTableName($GLOBALS['tb_prefix'].$this->table_name);
 	}

	function getCompanyInfo($companyid,$memberid = null,$cols = null)
	{
		$sql = "select ";
		if(empty($cols))
		$sql.= $this->common_cols;
		else
		$sql.= $cols;
		$sql.= " from ".$this->getTable(true)." where 1 ";
		if(!is_null($memberid)) $sql.=" and member_id=".$memberid;
		if(!is_null($companyid)) $sql.=" and id=".$companyid;
		$res = $GLOBALS['g_db']->GetRow($sql);
		return $res;
	}

	function statCompany()
	{
		$sql = "select type_id,count(Company.id) as Amount from ".$this->getTable(true)." group by Company.type_id";
		$return = $GLOBALS['g_db']->GetAll($sql);
		foreach ($return as $key=>$val) {
			$m[$val['type_id']] = $val['Amount'];
		}
		if($return) $m['sum'] = array_sum($m);
		return $m;
	}

	function update($posts, $action=null, $id=null, $tbname = null, $conditions = null){
		global $data;
		if(isset($data['Templet']['title'])){
			$cfg['templet_name'] = $data['Templet']['title'];
			$posts['configs'] = serialize($cfg);
		}
		return $this->save($posts, $action, $id, $tbname, $conditions);
	}

	function getTempletName($configs){
		$cfgs = unserialize($configs);
		return $cfgs['templet_name'];
	}

	function setConfigs($configs){
		$cfgs = unserialize($configs);
		$this->configs = $cfg;
	}

	function getConifigs(){
		return $this->configs;
	}

	function setMenu($pretend_level){
		global $_GET, $config_subdomain, $subdomain_support, $userid;
		if($subdomain_support){
		    $user_id = $userid; // From member-index.php
		}else{
		  $user_id = $_GET['userid'];
		}
		$tmp_menus = array();
		$tmp_host = uaGetHost(false);
		$tmp_menus['index'] = URL."space.php?do=home&userid=".$user_id;
		$tmp_menus['intro'] = URL."space.php?do=intro&userid=".$user_id;
		$tmp_menus['product'] = URL."space.php?do=product&userid=".$user_id;
		$tmp_menus['trade'] = URL."space.php?do=trade&userid=".$user_id;
		$tmp_menus['news'] = URL."space.php?do=news&userid=".$user_id;
		$tmp_menus['honour'] = URL."space.php?do=honour&userid=".$user_id;
		$tmp_menus['hr'] = URL."space.php?do=hr&userid=".$user_id;
		$tmp_menus['contact'] = URL."space.php?do=contact&userid=".$user_id;
		$tmp_menus['feedback'] = URL."space.php?do=feedback&userid=".$user_id;
		$this->menu = $tmp_menus;
	}

	function getMenu(){
		return $this->menu;
	}

	function checkStatus($company_id)
	{
		global $g_db, $tb_prefix;
		$sql = "select status,name from ".$tb_prefix."companies where id=".$company_id;
		$c_status = $g_db->GetRow($sql);
		if (!$c_status['status'] || empty($c_status['status'])) {
			flash(URL."room/tip.php", "./", sprintf(lgg("company_checking"), $c_status['name']), 0);
		}
	}
}
?>